package servlet;

import com.google.gson.Gson;
import dao.IndexAdvertisementDao;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "QueryIndexImagesServlet", value = "/QueryIndexImagesServlet.s")
public class QueryIndexAdvertisementServlet extends HttpServlet {

    IndexAdvertisementDao dao = new IndexAdvertisementDao();

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        List<Map<String, Object>> data1 = dao.selectAdvertisement();
        List<Map<String, Object>> data2 = dao.selectAdvertisement2();
        //返回json对象
        Map<String, Object> result = new HashMap<>();
        result.put("data1", data1);
        result.put("data2", data2);
        final String json = new Gson().toJson(result);
        response.getWriter().append(json);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
}
